package com.ruoyi.camp.service.impl;

import java.util.List;

import com.ruoyi.camp.domain.CampFacility;
import com.ruoyi.camp.mapper.CampFacilityMapper;
import com.ruoyi.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.camp.mapper.CFacilityMapper;
import com.ruoyi.camp.domain.CFacility;
import com.ruoyi.camp.service.ICFacilityService;

/**
 * 服务设施Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-01
 */
@Service
public class CFacilityServiceImpl implements ICFacilityService 
{
    @Autowired
    private CFacilityMapper cFacilityMapper;
    @Autowired
    private CampFacilityMapper campFacilityMapper;

    /**
     * 查询服务设施
     * 
     * @param fid 服务设施主键
     * @return 服务设施
     */
    @Override
    public CFacility selectCFacilityByFid(String fid)
    {
        return cFacilityMapper.selectCFacilityByFid(fid);
    }

    /**
     * 查询服务设施列表
     * 
     * @param cFacility 服务设施
     * @return 服务设施
     */
    @Override
    public List<CFacility> selectCFacilityList(CFacility cFacility)
    {
        return cFacilityMapper.selectCFacilityList(cFacility);
    }

    /**
     * 新增服务设施
     * 
     * @param cFacility 服务设施
     * @return 结果
     */
    @Override
    public int insertCFacility(CFacility cFacility)
    {
        return cFacilityMapper.insertCFacility(cFacility);
    }
    @Override
    public int insertCampFacility(String campId, String[] facilityIds) {
        //先删除营地下的服务设施
        campFacilityMapper.deleteCFacilityByCampId(campId);
        //然后插入新的服务设施
        for (String facilityId : facilityIds) {
            CampFacility campFacility = new CampFacility();
            campFacility.setCfid(IdUtils.randomUUID());
            campFacility.setCampid(campId);
            campFacility.setFacilityid(facilityId);
            campFacilityMapper.insertCampFacility(campFacility);
        }
        return 1;
    }
    /**
     * 修改服务设施
     * 
     * @param cFacility 服务设施
     * @return 结果
     */
    @Override
    public int updateCFacility(CFacility cFacility)
    {
        return cFacilityMapper.updateCFacility(cFacility);
    }

    /**
     * 批量删除服务设施
     * 
     * @param fids 需要删除的服务设施主键
     * @return 结果
     */
    @Override
    public int deleteCFacilityByFids(String[] fids)
    {
        return cFacilityMapper.deleteCFacilityByFids(fids);
    }

    /**
     * 删除服务设施信息
     * 
     * @param fid 服务设施主键
     * @return 结果
     */
    @Override
    public int deleteCFacilityByFid(String fid)
    {
        return cFacilityMapper.deleteCFacilityByFid(fid);
    }

    @Override
    public int deleteCFacilityByCampId(String campid) {
        return campFacilityMapper.deleteCFacilityByCampId(campid);
    }
}
